﻿using System;

using Storm.TextEditor.Drawing.GDI;

namespace Storm.TextEditor.Drawing
{
    /// <summary>
    /// Represents a class used by the DefaultPainter to hold brushes.
    /// </summary>
    public class RenderItems
        : IDisposable
    {
        #region Fields

        #region GDISurfaces

        private GDISurface backBuffer = null;
        private GDISurface selectionBuffer = null;
        private GDISurface stringBuffer = null;

        #endregion

        #region GDIFonts

        private GDIFont fontNormal = null;
        private GDIFont fontBold = null;
        private GDIFont fontItalic = null;
        private GDIFont fontUnderline = null;

        private GDIFont fontBoldItalic = null;
        private GDIFont fontBoldUnderline = null;
        private GDIFont fontItalicUnderline = null;
        private GDIFont fontBoldItalicUnderline = null;

        #endregion

        #region GDIBrushes

        private GDIBrush gutterMarginBrush = null;
        private GDIBrush gutterMarginBorderBrush = null;

        private GDIBrush lineNumberMarginBrush = null;
        private GDIBrush lineNumberMarginBorderBrush = null;

        private GDIBrush backgroundBrush = null;
        private GDIBrush highlightLineBrush = null;
        private GDIBrush outlineBrush = null;
        private GDIBrush collapsedBackgroundBrush = null;
        private GDIBrush symbolBrush = null;
        private GDIBrush expansionBackgroundBrush = null;

        #endregion

        #endregion

        #region Properties

        #region GDISurfaces

        /// <summary>
        /// Gets or sets the BackBuffer field of the RenderItems.
        /// </summary>
        public GDISurface BackBuffer
        {
            get { return backBuffer; }
            set { backBuffer = value; }
        }

        /// <summary>
        /// Gets or sets the SelectionBuffer field of the RenderItems.
        /// </summary>
        public GDISurface SelectionBuffer
        {
            get { return selectionBuffer; }
            set { selectionBuffer = value; }
        }

        /// <summary>
        /// Gets or sets the StringBuffer field of the RenderItems.
        /// </summary>
        public GDISurface StringBuffer
        {
            get { return stringBuffer; }
            set { stringBuffer = value; }
        }

        #endregion

        #region GDIFonts

        /// <summary>
        /// Gets or sets the FontNormal field of the RenderItems.
        /// </summary>
        public GDIFont FontNormal
        {
            get { return fontNormal; }
            set { fontNormal = value; }
        }

        /// <summary>
        /// Gets or sets the FontBold field of the RenderItems.
        /// </summary>
        public GDIFont FontBold
        {
            get { return fontBold; }
            set { fontBold = value; }
        }

        /// <summary>
        /// Gets or sets the FontItalic field of the RenderItems.
        /// </summary>
        public GDIFont FontItalic
        {
            get { return fontItalic; }
            set { fontItalic = value; }
        }

        /// <summary>
        /// Gets or sets the FontUnderline field of the RenderItems.
        /// </summary>
        public GDIFont FontUnderline
        {
            get { return fontUnderline; }
            set { fontUnderline = value; }
        }

        /// <summary>
        /// Gets or sets the FontBoldItalic field of the RenderItems.
        /// </summary>
        public GDIFont FontBoldItalic
        {
            get { return fontBoldItalic; }
            set { fontBoldItalic = value; }
        }

        /// <summary>
        /// Gets or sets the FontBoldUnderline field of the RenderItems.
        /// </summary>
        public GDIFont FontBoldUnderline
        {
            get { return fontBoldUnderline; }
            set { fontBoldUnderline = value; }
        }

        /// <summary>
        /// Gets or sets the FontItalicUnderline field of the RenderItems.
        /// </summary>
        public GDIFont FontItalicUnderline
        {
            get { return fontItalicUnderline; }
            set { fontItalicUnderline = value; }
        }

        /// <summary>
        /// Gets or sets the FontBoldItalicUnderline field of the RenderItems.
        /// </summary>
        public GDIFont FontBoldItalicUnderline
        {
            get { return fontBoldItalicUnderline; }
            set { fontBoldItalicUnderline = value; }
        }

        #endregion

        #region GDIBrushes

        /// <summary>
        /// Gets or sets the GutterMarginBrush field of the RenderItems.
        /// </summary>
        public GDIBrush GutterMarginBrush
        {
            get { return gutterMarginBrush; }
            set { gutterMarginBrush = value; }
        }

        /// <summary>
        /// Gets or sets the GutterMarginBorderBrush field of the RenderItems.
        /// </summary>
        public GDIBrush GutterMarginBorderBrush
        {
            get { return gutterMarginBorderBrush; }
            set { gutterMarginBorderBrush = value; }
        }

        /// <summary>
        /// Gets or sets the LineNumberMarginBrush field of the RenderItems.
        /// </summary>
        public GDIBrush LineNumberMarginBrush
        {
            get { return lineNumberMarginBrush; }
            set { lineNumberMarginBrush = value; }
        }

        /// <summary>
        /// Gets or sets the LineNumberMarginBorderBrush field of the RenderItems.
        /// </summary>
        public GDIBrush LineNumberMarginBorderBrush
        {
            get { return lineNumberMarginBorderBrush; }
            set { lineNumberMarginBorderBrush = value; }
        }

        /// <summary>
        /// Gets or sets the BackgroundBrush field of the RenderItems.
        /// </summary>
        public GDIBrush BackgroundBrush
        {
            get { return backgroundBrush; }
            set { backgroundBrush = value; }
        }

        /// <summary>
        /// Gets or sets the HighlightLineBrush field of the RenderItems.
        /// </summary>
        public GDIBrush HighlightLineBrush
        {
            get { return highlightLineBrush; }
            set { highlightLineBrush = value; }
        }

        /// <summary>
        /// Gets or sets the OutlineBrush field of the RenderItems.
        /// </summary>
        public GDIBrush OutlineBrush
        {
            get { return outlineBrush; }
            set { outlineBrush = value; }
        }

        /// <summary>
        /// Gets or sets the CollapsedBackgroundBrush field of the RenderItems.
        /// </summary>
        public GDIBrush CollapsedBackgroundBrush
        {
            get { return collapsedBackgroundBrush; }
            set { collapsedBackgroundBrush = value; }
        }

        /// <summary>
        /// Gets or sets the SymbolBrush field of the RenderItems.
        /// </summary>
        public GDIBrush SymbolBrush
        {
            get { return symbolBrush; }
            set { symbolBrush = value; }
        }

        /// <summary>
        /// Gets or sets the ExpansionBackgroundBrush field of the RenderItems.
        /// </summary>
        public GDIBrush ExpansionBackgroundBrush
        {
            get { return expansionBackgroundBrush; }
            set { expansionBackgroundBrush = value; }
        }

        #endregion

        #endregion

        #region IDisposable Members

        /// <summary>
        /// Removes the RenderItems and its children.
        /// </summary>
        public void Dispose()
        {
            if (backBuffer != null)
            {
                backBuffer.Dispose();
                backBuffer = null;
            }

            if (selectionBuffer != null)
            {
                selectionBuffer.Dispose();
                selectionBuffer = null;
            }

            if (stringBuffer != null)
            {
                stringBuffer.Dispose();
                stringBuffer = null;
            }

            if (fontNormal != null)
            {
                fontNormal.Dispose();
                fontNormal = null;
            }

            if (fontBold != null)
            {
                fontBold.Dispose();
                fontBold = null;
            }

            if (fontItalic != null)
            {
                fontItalic.Dispose();
                fontItalic = null;
            }

            if (fontBoldItalic != null)
            {
                fontBoldItalic.Dispose();
                fontBoldItalic = null;
            }

            if (fontUnderline != null)
            {
                fontUnderline.Dispose();
                fontUnderline = null;
            }

            if (fontBoldUnderline != null)
            {
                fontBoldUnderline.Dispose();
                fontBoldUnderline = null;
            }

            if (fontItalicUnderline != null)
            {
                fontItalicUnderline.Dispose();
                fontItalicUnderline = null;
            }

            if (fontBoldItalicUnderline != null)
            {
                fontBoldItalicUnderline.Dispose();
                fontBoldItalicUnderline = null;
            }

            if (gutterMarginBrush != null)
            {
                gutterMarginBrush.Dispose();
                gutterMarginBrush = null;
            }

            if (gutterMarginBrush != null)
            {
                gutterMarginBrush.Dispose();
                gutterMarginBrush = null;
            }

            if (lineNumberMarginBrush != null)
            {
                lineNumberMarginBrush.Dispose();
                lineNumberMarginBrush = null;
            }

            if (lineNumberMarginBorderBrush != null)
            {
                lineNumberMarginBorderBrush.Dispose();
                lineNumberMarginBorderBrush = null;
            }

            if (backgroundBrush != null)
            {
                backgroundBrush.Dispose();
                backgroundBrush = null;
            }

            if (highlightLineBrush != null)
            {
                highlightLineBrush.Dispose();
                highlightLineBrush = null;
            }

            if (outlineBrush != null)
            {
                outlineBrush.Dispose();
                outlineBrush = null;
            }
        }

        #endregion
    }
}
